(function ($, doc) {
	var state = app.getState();
	var uid = state.user_id;

	$.init({
		beforeback: function () {
			var targetWnd = plus.webview.getWebviewById('pages/wallet/wallet.html');
			$.fire(targetWnd, 'refreshWnd', {});
			return true;
		}
	});

	window.onload = function () {
		var getUrl = apiurl + "wallet/index/?user_id=" + uid;
		$.getJSON(getUrl, function (res) {
			if (res.status == 1) {
				var add = template('list-template', {
					"wallets": res.data
				});

				doc.getElementById("walletslist").innerHTML = add;
			}
		});
	}

	$("#walletslist").on("tap", "a", function () {
		var targets = this.getAttribute("href") + "?" + this.getAttribute("value");
		mui.openWindow({
			url: targets,
			id: targets
		});
	});



	var clipboard = new Clipboard('#wallet_address_input');
	clipboard.on('success', function (e) {
		console.log(e);
		mui.toast("已复制钱包地址");
	});
	/*	window.addEventListener('refresh', function (e) { //执行刷新
			location.reload();
		});*/
}(mui, document));

function copyaddress(obj) {
	var data = obj.getAttribute("data-clipboard-text");
	var objd = document.getElementById('wallet_address_input');
	var dist = objd.setAttribute("data-clipboard-text", data);
	objd.click();
}

function updateDefalut(obj, user_id, walletid) {
	var getUrl = apiurl + "wallet/updateDefault?user_id=" + user_id + "&wallet_id=" + walletid;
	mui.getJSON(getUrl, function (res) {
		if (res.status == 1) {
			var ws = document.querySelectorAll(".mui-badge");
			for (var i = 0; i < ws.length; i++) {
				if (ws[i].id == walletid)
					ws[i].style.display = "";
				else {
					ws[i].style.display = "none";
				}
			}
		}
	});
}